package com.fan.teamer.model.dao;

import java.util.List;

import javax.inject.Named;

import org.hibernate.SessionFactory;

import com.fan.teamer.model.domain.Member;

@Named("memberDao")
public class MemberDaoImpl implements MemberDao {

	private SessionFactory sessionFactory;

	/**
	 * Get Hibernate Session Factory
	 * 
	 * @return SessionFactory - Hibernate Session Factory
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * Set Hibernate Session Factory
	 * 
	 * @param SessionFactory
	 *            - Hibernate Session Factory
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public Member getMember(String email) {
		Member member = (Member) sessionFactory.getCurrentSession().get(
				Member.class, email);
		return member;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Member> getAllMembers() {
		List<Member> list = sessionFactory.getCurrentSession()
				.createCriteria(Member.class).list();
		return list;
	}

	@Override
	public int getSize() {
		return getAllMembers().size();
	}

	@Override
	public void addMember(Member member) {
		sessionFactory.getCurrentSession().save(member);
	}

	@Override
	public void updateStock(Member member) {
		sessionFactory.getCurrentSession().update(member);
	}

	@Override
	public void deleteMember(Member member) {
		sessionFactory.getCurrentSession().delete(member);
	}

	@Override
	public boolean hasMember(String email) {
		if (getMember(email) == null)
			return false;
		else
			return true;
	}

	@Override
	public List<String> getColumnNames() {
		// TODO Auto-generated method stub
		return null;
	}

}
